package psn.kiko.mapper.ddl.table.column;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 查看某个库(schema)的某张表(table)的列的详细信息列表
 */
@Mapper
public interface TableColumnsMapper {
	/**
	 * 查看某数据库的某张表的详细信息
	 * @param schema 数据库名
	 * @param table 表名
	 * @return 某个数据库某张表的列的信息列表
	 */
	@Select("SELECT\n" +
			"c.TABLE_NAME,\n" +
			"c.COLUMN_NAME,\n" +
			"c.COLUMN_DEFAULT,\n" +
			"c.DATA_TYPE,\n" +
			"c.COLUMN_TYPE,\n" +
			"c.CHARACTER_MAXIMUM_LENGTH,\n" +
			"c.IS_NULLABLE,\n" +
			"c.COLUMN_COMMENT,\n" +
			"c.`PRIVILEGES`\n" +
			"FROM\n" +
			"information_schema.`COLUMNS` AS c\n" +
			"WHERE c.TABLE_SCHEMA='${schema}' AND c.TABLE_NAME = '${table}';")
	List<Map<String,Object>> columnsOfTable(@Param("schema") String schema ,
	                                                        @Param("table") String table);
}
